Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The change uses rendered widths for constrained pixel resizing and adds regression tests for the affected first-drag scenarios, with no active review issues identified.
No open issues 🎉
What changed in this PR
Fixes grid column resizing so pixel drags start from the column’s rendered width when minWidth constrains its configured width.
Changes:
- Uses rendered widths for pixel resize calculations and event metadata.
- Adds regression tests for constrained and first-drag scenarios.
| File | Description |
|---|---|
| projects/igniteui-angular/grids/grid/src/column-resizing.spec.ts | Adds regression tests covering first-drag resizing with minimum and user-defined widths. |
| projects/igniteui-angular/grids/core/src/resizing/resizing.service.ts | Uses the rendered column width as the baseline for pixel resizing and resize event metadata. |
Review effort: Lite
onlyexeption
left a comment
There was a problem hiding this comment.
Thanks for the fix and the detailed write-up! I checked the branch out and dragged the columns in the demo app. The pixel cases from #18038 now end exactly where the resize indicator is released. Your change also fixes a few related cases: a column without width drawn at its maxWidth, the tree grid, the hierarchical grid and multi-row layouts. The new tests fail on master and pass with the change.
There's one thing to address before merging, plus a few smaller suggestions.
Percentage-width columns still ignore the first drag
_handlePercentageResize() has the same root cause: it still starts from parseFloat(column.width). A column with a percentage width is drawn at its minWidth whenever its share of the grid is smaller than the minWidth and at its maxWidth whenever the share is larger. Since #15449 (for #15383) this also applies when the grid first renders.
This is the main reason to set a minWidth on a percentage column. It's also the configuration the column resizing docs use for restricting resizing:
<igx-column [field]="'ID'" width="10%" [resizable]="true"
[minWidth]="'60px'" [maxWidth]="'230px'"></igx-column>The docs say the width "may be defined in pixels, percentages or a mix of both" and "Mixing the minimum and maximum column width value types (pixels or percentages) is allowed." For percentage columns they add: "The columns remain responsive and any future grid resizing will still reflect on the columns as well." A percentage width keeps the column responsive, and the pixel minWidth keeps it readable on narrow screens. On a narrow screen the column is therefore drawn at its minWidth most of the time, which is exactly the state this bug hits.
Here is the docs example in a 500px grid, where 10% is 50px, so the column is drawn at its 60px minWidth:
| First drag | Expected | With this PR |
|---|---|---|
| +8px | 68px | 60px (no change) |
| +20px | 80px | ~70px |
| +40px | 100px | ~90px |
The same happens with maxWidth. For example, with width="50%" and maxWidth="300px" in a 1000px grid, a −40px drag leaves the column at 300px. A percentage minWidth behaves the same way.
One way to fix it is to start from the drawn width converted to a percentage of grid.calcWidth, but only when the column is drawn at a different width than its percentage. Converting unconditionally isn't safe: the round trip is not exact (20% of a 641px grid comes back as 20.000000000000004%). An unconstrained column would then get a slightly different stored value on every resize, and the noise would show up in prevWidth. A sketch:
protected getResizeStartPercent(column: ColumnType): number {
const percentWidth = parseFloat(column.width);
const gridWidth = column.grid.calcWidth;
const drawnWidth = parseFloat(String(column.calcWidth));
// In a grid without a width, percentage columns are drawn at their minimum whatever the percentage.
if (!gridWidth || column.grid.isColumnWidthSum || !Number.isFinite(drawnWidth)) {
return percentWidth;
}
// Compare in pixels: converting the drawn width back to a percentage is not exact.
const isDrawnAtWidth = Math.abs(drawnWidth - percentWidth / 100 * gridWidth) < 0.01;
return isDrawnAtWidth ? percentWidth : drawnWidth / gridWidth * 100;
}Use it in _handlePercentageResize() and for the percentage prevWidth in resizeColumn(). The column keeps its % unit, so it stays responsive.
For tests, I'd cover a percentage width with a pixel minWidth, one with a pixel maxWidth, and one with a percentage minWidth. Also add an unconstrained percentage column on a 641px grid that asserts the exact % string. The existing percentage tests use round numbers like '50%' and '12.5%', so they wouldn't catch the float noise.
Smaller suggestions
-
Releasing the resize handle without moving it still changes
width. Hold the handle longer than the 200ms debounce and release it without moving. A column drawn at itsminWidthgets that width as itswidth:'136px'becomes'200px'andwidthSetByUserbecomestrue. In the demo app, a10%column with a120pxminWidthbecame12.51%after such a click. Once the window got wider, it was drawn at 144px instead of 120px. Master does this too, but with this PR the pixel case no longer emitscolumnResized, so the change goes unreported. An early return inresizeColumn()whendiff === 0fixes it. Keepthis.zone.run(() => { })andthis.isColumnResizing = falsein that branch so the resize line still hides. -
getResizeStartWidth()can be simplified. The|| column.widthin the first line is redundant, because the second line already falls back tocolumn.width. The result is the same for numbers,0,null,undefined,NaNand strings:const calcWidth = parseFloat(String(column.calcWidth)); return Number.isFinite(calcWidth) ? calcWidth : parseFloat(column.width);
-
Tests for the other cases this PR fixes:
- A column without
widththat is drawn at itsmaxWidth. Example: a 900px grid with three columns withoutwidth, one of them withmaxWidth="100px". That column reportscolumn.widthas'400px'but is drawn at 100px. On master a −15px drag leaves it at 100px, and nothing covers this case yet. - Multi-row layouts. They go through
resizeColumnLayoutFor()and then_handlePixelResize(), which now starts fromcalcWidthtoo. Add a test ingrid.multi-row-layout.integration.spec.tswith a child that has aminWidthand nowidth. On master its template column stays at200pxafter a +40px drag. - In "should resize a column with minWidth below the default minimum…", consider asserting the precondition, for example
expect(parseFloat(column.width)).not.toEqual(drawnWidth), like the other three tests do with'136px'and'100px'. Otherwise the test keeps passing even if its setup stops reproducing the bug.
- A column without
-
CHANGELOG. Please add an entry under a new
## 22.3.3>### Bug Fixessection (22.3.2 is already released). Merging master first brings in the current sections. It's worth mentioning thecolumnResizedchange too:prevWidthis now the drawn width ('200px'rather than'136px'), and a drag that leaves the drawn width unchanged no longer emits the event.
Happy to re-test once you push an update.
315d513 to
9ca9376
Compare
A resizable column with minWidth but no width reported its clamped default width (136px) through column.width while it was drawn at its minWidth. _handlePixelResize started from column.width, so the first drag was clamped back to minWidth and a longer drag undershot by the same difference. Start pixel resizes (and the columnResized prevWidth) from calcWidth, which holds the drawn width, falling back to column.width when it is not finite. Fixes IgniteUI#18038
Percentage columns drawn at minWidth/maxWidth now start the first drag from the drawn width via getResizeStartPercent, and a no-move release no longer assigns the drawn width or emits columnResized.
9ca9376 to
0e0a48c
Compare
Description
Fixes #18038
A resizable column with
minWidthbut nowidthignored the first drag:column.widthreports the clamped default width (136px) while the column is drawn at itsminWidth(e.g.200px)._handlePixelResize()started fromcolumn.width, so a first drag shorter thanminWidth - 136pxwas clamped back tominWidth(no visible change), and a longer drag undershot by the same difference (+100px gave 236px instead of 300px).The fix starts pixel resizes from the width the column is actually drawn at: the new
getResizeStartWidth()returnscalcWidthwhen finite, falling back tocolumn.widthotherwise. It is used by_handlePixelResize()and byresizeColumn()for thecolumnResizedevent'sprevWidth(percentage resizes are untouched). This matches the precedent inresizeColumnLayoutFor(), which already starts fromcalcWidth, and inrestrictResizeMin/Max/getColMinWidth, which already use the rendered width.Reproduction (before the fix)
Base SHA:
aba881361dcaa92a70a880b1fd848a9cab049ecc(master)New tests in
projects/igniteui-angular/grids/grid/src/column-resizing.spec.ts(run withCI=true npx ng test igniteui-angular --no-watch --browsers=chromiumHeadless --include 'projects/igniteui-angular/grids/grid/src/column-resizing.spec.ts' --filter '#18038'):minWidth200px, nowidth)200px240px236px300pxwidth100px +minWidth200px200px240pxminWidth50px (below the 136px default)50px90pxAll four fail before the fix (verified by stashing only the service change) and pass after it.
Control case
A second +40px drag in the first test still works as before:
240px→280px, and thecolumnResizedevent now reports the correct args ({ prevWidth: '200px', newWidth: '240px' }for the first drag,{ prevWidth: '240px', newWidth: '280px' }for the second).Regression scope
column-resizing.spec.ts: 54 passed, 2 failed — the same 2Multi Column Headersautosize tests fail on cleanmastertoo (verified by agit stashbaseline run; they depend on webfonts loaded from Google Fonts, which are unavailable in this environment). No other test in the file changed outcome.npm run lint:libexits 0 (warnings only, matching the file's existingChangeDetectionStrategy.Eagertest-component convention).Diff scope
projects/igniteui-angular/grids/core/src/resizing/resizing.service.ts(+14/−2): newgetResizeStartWidth()helper, used by_handlePixelResize()andresizeColumn()(non-percentage path only).projects/igniteui-angular/grids/grid/src/column-resizing.spec.ts(+199): 4 new tests + 3 new test components. No other files changed.Risks checked and ruled out
calcWidthequals the drawn width: templates bind toresolvedWidth = calcPixelWidth + 'px', i.e.calcWidth; for user-set widthscacheCalcWidthconstrainswidththroughgetConstrainedSizePx, so it is the drawn width there too. Multi-row-layout resize already usedcalcWidthas its start width.isPercentageWidthguard inresizeColumn()); the pivot-grid resizing service has nominWidthon its dimensions, so the same mismatch cannot occur there.calcWidthduring a drag does not mutate layout state:getCalcWidth()returns the cached value whenever it is set and finite, which is the normal case during a drag.columnResizedevent (prevWidth: '136px'→newWidth: '200px'for a column that did not visibly change).Known limitation (out of scope)
If every visible column is set/constrained and their constrained widths sum to exactly the grid width,
getPossibleColumnWidth()computes0/0 = NaN, which can leavecolumn.widthas"NaNpx"in that knife-edge case. That is a pre-existing issue in the width-calculation path, not something this fix introduces; the-Infinitysibling of the same expression is handled (getConstrainedSizePx(-Infinity)returns theminWidth, covered by theminWidth50px test).